home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d20 / yuck_200.arc / YUCK.H < prev    next >
C/C++ Source or Header  |  1990-10-29  |  15KB  |  252 lines

  1. /* ------------------------------------------------------------------------- */
  2. /*                                                                           */
  3. /*                                                                           */
  4. /*                                                                           */
  5. /*                                                                           */
  6. /*                                                                           */
  7. /*                                                                           */
  8. /*                                                                           */
  9. /*                                                                           */
  10. /*                                                                           */
  11. /*                         Militantly Public Domain                          */
  12. /*                                                                           */
  13. /*                                                                           */
  14. /*                                                                           */
  15. /*                                                                           */
  16. /*                                                                           */
  17. /*                                                                           */
  18. /*                                                                           */
  19. /*                                                                           */
  20. /*                                                                           */
  21. /*                                                                           */
  22. /* ------------------------------------------------------------------------- */
  23. /* If you find a way to replace a girlfriend on vacation with Yuck!, I'd     */
  24. /* like to hear about it <sigh, sniff, boohoo>.                              */
  25. /* ========================================================================= */
  26. /* MS-DOS (MS-C 5.10): "cl -nologo -Ox -AC -Gt2048 -W3 yuck.c yucknl.c"      */
  27. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  28. /* Amiga (Lattice C 5.04): "lc -L -O yuck"                                   */
  29. /* ========================================================================= */
  30. /* Yuck! 1.50 is cleaned up a lot (towards portability), and the TrapDoor    */
  31. /* people (Max Hantsch and Martin Laubach, 2:310/6) have implemented the     */
  32. /* necessary changes to get Yuck! to run on Amiga type machines. #define the */
  33. /* identifier AMIGA to get the AMIGA version. Thanks to Max and mjl.         */
  34. /* ========================================================================= */
  35. /* Yuck! 1.70 isolates a few functions into yucknl.c so that i can rewrite   */
  36. /* the crap in assembler without worrying about the Amiga version. intention */
  37. /* is to make the asm- and c-versions of those functions plug-compatible.    */
  38. /* ------------------------------------------------------------------------- */
  39. /* Yuck! 1.80 craps this idea. I did implement it, and it was quite a lot    */
  40. /* faster than the regular version, but the difference of 3 seconds (on a    */
  41. /* total time of 14 for all four lists) is just not worth the trouble of     */
  42. /* keeping two versions up-to-date.                                          */
  43. /* ========================================================================= */
  44. /* uncomment the following define to compile an Amiga version                */
  45. /* #define    AMIGA        1 */
  46. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  47. /* uncomment the following define to increase file buffer size to FBUFSIZ    */
  48. #define    BIGBUF        1
  49. #if    defined( BIGBUF )                           /* what about buffering? */
  50. #define    FBUFSIZ        2048                             /* file buffer size */
  51. #endif                                                             /* BIGBUF */
  52. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  53. /* uncomment the following define to have the MSC-5.1 optimizer die a quick  */
  54. /* and sudden death. will break only when compiled with max optimization.    */
  55. /* at least, this worked with 1.30; didn't try for later releases.           */
  56. /* #define    BREAK_MSC    1 */
  57. /* ------------------------------------------------------------------------- */
  58. #include <stdio.h>
  59. #include <stdlib.h>
  60. #include <string.h>
  61. #include <dos.h>
  62. #if    ! defined( AMIGA )
  63. #include <malloc.h>
  64. #include <process.h>
  65. #else                                                               /* AMIGA */
  66. #include <exec/types.h>
  67. #include <exec/memory.h>
  68. #include <proto/exec.h>
  69. #endif                                                              /* AMIGA */
  70. /* ------------------------------------------------------------------------- */
  71. #if    defined( AMIGA )
  72. #define    VER_MACH    "[Amiga]"
  73. #define    O_RT        "ra"             /* open for read in translated mode */
  74. #define    O_WB        "wb"          /* open for write in untranslated mode */
  75. #define    WILDCARD    ".#?"
  76. #define    FFNAME        fb->fib_FileName
  77. #define    MAILDIR        "Mail:"
  78. #define    hfree        free
  79. #define    halloc(num,siz)    malloc( (num) * (siz) )
  80. #define    SORTCMD        "sort {in} {out}"            /* default sort command */
  81. #define    SORTTEMP    "Yuck!.temp"               /* default temp file name */
  82. #else                                                               /* AMIGA */
  83. #define    VER_MACH    "[MS-DOS]"
  84. #define    O_RT        "rt"             /* open for read in translated mode */
  85. #define    O_WB        "wb"          /* open for write in untranslated mode */
  86. #define    WILDCARD    ".*"
  87. #define    FFNAME        fb.name
  88. #define    SORTCMD        "qsort {in} {out}"           /* default sort command */
  89. #define    SORTTEMP    "yucktemp.$$$"             /* default temp file name */
  90. #endif                                                              /* AMIGA */
  91. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  92. #define    VER_NAME    "Yuck! 2.00 (" __DATE__ ", " __TIME__ ") "
  93. #define    VER        VER_NAME VER_MACH
  94. #define    HDR        ";S A %s pointlist generated by %s -- fake CRC 1 : 0%s"
  95. #define assert(b,l)    { \
  96.                 if ( strlen( b ) > l ) \
  97.                     printf( "\nassert: '%s'>%u at %s/%u\n", \
  98.                     b, l, __FILE__, __LINE__ ); \
  99.                 }
  100. #define    skip(s)        for ( ; *s && ( *s == ' ' || *s == '\t' ); s ++ )
  101. #define    nskip(s)    for ( ; *s && ( *s != ' ' && *s != '\t' ); s ++ )
  102. /* ========================================================================= */
  103. #if    ! defined( _ALEX_TYPES )                             /* my own types */
  104. typedef    enum        { No, Yes }    YesNo;    /* I don't like "booleans" */
  105. typedef    unsigned char    Byte;                      /* guess what this one is */
  106. typedef    unsigned short    Word;
  107. #define    _ALEX_TYPES    1
  108. #endif
  109. #define    CR        "\r"                                /* these are ... */
  110. #define    LF        "\n"                              /* ... allowed ... */
  111. #define    CRLF        "\r\n"                       /* ... line terminators */
  112. #define    EOS        ( (Byte) '\0' )                 /* string terminator */
  113. #define    STRSIZ        39                        /* usable chars in a field */
  114. #define    MAPINC        32                    /* chunk size for "map" allocs */
  115. #define    MAXKILL        8                          /* max. # of nets to kill */
  116. #define    MAXUKILL    8           /* max. # of nodes to kill from userlist */
  117. #define    MAXTIM        32                      /* max # of tim_fake entries */
  118. #define    MAXINC        8         /* max. # of ranges to include in "oldnet" */
  119. #define    MAXARGS        64                     /* max tokens in sort command */
  120. #define    CFGNAME        "yuck.ctl"                   /* default control file */
  121. #define    N109FCHR    ':'                    /* trigger char 1 for tim_net */
  122. #define    N109CHR        '/'                    /* trigger char 2 for tim_net */
  123. #define    POINTNAME    ""                                  /* see "sysname" */
  124. #define    POINTLOC    "Somewhere"                          /* see "sysloc" */
  125. #define    POINTFLAGS    "MO"                               /* see "userlist" */
  126. #define    POINTBAUD    2400                               /* see "userlist" */
  127. #define POINTADDR    38       /* column after which to search for address */
  128. /* ========================================================================= */
  129. typedef    enum    { Zone, Region, Host, Hub, Node, Point, Hold, Pvt, Down } eTyp;
  130. static    Byte *    aTyp[] = { "Zone", "Region", "Host", "Hub", "", "Point",
  131.                "Hold", "Pvt", "Down" };
  132. /* ------------------------------------------------------------------------- */
  133. typedef    struct    _tAd    {
  134.     Word    z, n, f, p;
  135.     }    tAd;
  136. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  137. typedef    struct    _tInc    {                           /* include statement def */
  138.     eTyp    Type;                                /* zone, region or net? */
  139.     YesNo    incHdr;                          /* hdr & independents only? */
  140.     tAd    a;                                     /* address referenced */
  141.     }    tInc;
  142. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  143. /* this is the node structure size, less any fill bytes.                     */
  144. typedef    struct    _tNod    {
  145.     struct    _tNod *    nx;                                  /* next element */
  146.     eTyp    Type;
  147.     YesNo    ok;            /* == No if not filled in ==> search nodelist */
  148.     YesNo    prcd;                         /* == Yes if already processed */
  149.     tAd    a;
  150.     Word    No;
  151.     Byte    Bbs[STRSIZ + 1], City[STRSIZ + 1],
  152.         Sysop[STRSIZ + 1], Tel[STRSIZ + 1];
  153.     Byte    Flags[STRSIZ + 1];
  154.     Word    Baud;
  155.     }    tNod;
  156. /* ------------------------------------------------------------------------- */
  157. typedef    struct    _tCfg    {
  158.     YesNo    killInput;             /* must kill input file after proc'g? */
  159.     YesNo    killUserlist;          /* must kill input file after proc'g? */
  160.     YesNo    killInfd199b;          /* must kill input file after proc'g? */
  161.     YesNo    keepPvt;          /* == Yes if private points should be kept */
  162.     YesNo    putUnpub;                         /* insert "-Unpublished-"? */
  163.     YesNo    N109;                                     /* net_109 kludge? */
  164.     YesNo    Fd199b;                          /* flag for 1.99b pointlist */
  165.     YesNo    Clist;                        /* flag for Amiga Clist format */
  166.     YesNo    Oldnet;                     /* flag for old format pointlist */
  167.     YesNo    doInclude;                             /* "outfile -a" used? */
  168.     YesNo    uoInclude;                             /* "userout -a" used? */
  169.     YesNo    haveProlog;                 /* == Yes if prolog file defined */
  170.     YesNo    haveEpilog;                 /* == Yes if epilog file defined */
  171.     YesNo    havePointnet;                    /* == Yes if "infile" found */
  172.     YesNo    haveUserlist;                  /* == Yes if "userlist" found */
  173.     YesNo    haveInfd199b;             /* == Yes if "infd199b" is present */
  174.     YesNo    haveUserout;                    /* == Yes if "userout" found */
  175.     YesNo    haveSysname;          /* == Yes is system name not defaulted */
  176.     YesNo    trimJunk;                              /* trim tim_net junk? */
  177.     Word    myZone;         /* zone number, if not present in input file */
  178.     int    maxkill;                                /* # of kill entries */
  179.     int    maxukill;                      /* # of userlist kill entries */
  180.     int    maxmap;                                  /* # of map entries */
  181.     int    maxinc;                   /* "include" entries actually used */
  182.     int    maxtim;                             /* current # of tim_fake */
  183.     Word    killNet[MAXKILL];                      /* nets to be removed */
  184.     Word    timfake[MAXTIM];                            /* tim_fake data */
  185.     tAd    killUser[MAXUKILL]; /* pointnets to be removed from userlist */
  186.     Word *    mapNet;                                 /* remap source nets */
  187.     tAd *    mapAd;                             /* remap target addresses */
  188.     Word    fakenet;                      /* fakenet default for tim_net */
  189.     tInc    incNet[MAXINC];            /* include these into an "oldnet" */
  190.     Byte    termUser[4];                      /* userout line terminator */
  191.     Byte    termOldnet[4];                     /* oldnet line terminator */
  192.     Byte    termFd199b[4];                     /* fd199b line terminator */
  193.     Byte    termClist[4];                       /* clist line terminator */
  194.     Byte    sysName[40];                                   /* "userlist" */
  195.     Byte    sysLoc[40];                                    /* "userlist" */
  196.     Byte    sysFlags[40];                                  /* "userlist" */
  197.     Byte    iFile[80];                                 /* input filename */
  198.     Byte    bFile[80];                              /* infd199b filename */
  199.     Byte    uFile[80];                              /* userlist filename */
  200.     Byte    oFile[80];                         /* oldnet output filename */
  201.     Byte    nFile[80];                               /* current nodelist */
  202.     Byte    fFile[80];                         /* fd199b output filename */
  203.     Byte    cFile[80];                          /* clist output filename */
  204.     Byte    lFile[80];                       /* userlist output filename */
  205.     Byte    pFile[80];                                    /* prolog file */
  206.     Byte    eFile[80];                                    /* epilog file */
  207.     Byte    tFile[80];                             /* pre-sort temp file */
  208.     Byte    Sort[128];                              /* sort command line */
  209.     }    tCfg;
  210. /* ========================================================================= */
  211. extern    tNod *    pts;                                        /* start of list */
  212. extern    int    maxpt;                              /* next free point entry */
  213. extern    int    lastpolz;        /* index of last include selected by polz() */
  214. extern    Word    MAXMAP;                          /* current allocated "map"s */
  215. extern    YesNo    inPointnet;                       /* flag var for parseRec() */
  216. extern    YesNo    inFd199b;                         /* flag var for parseRec() */
  217. extern    tCfg    Cfg;                                 /* configuration record */
  218. /* ========================================================================= */
  219. /*                       externally defined functions                        */
  220. tNod *    addNod( int addCopy, tNod * Node );
  221. void    copyProlog( FILE * of, Byte * name, Byte * term );
  222. void    delNod( tNod * p );
  223. void    dumpList( void );
  224. void    dumpRec( tNod * b, FILE * o, int nl );
  225. int    find( Word ln, Word * p, int n );
  226. int    get109( Byte * str, Word * net, Word * nod );
  227. Byte *    getComma( Byte * p, Byte * Temp );
  228. Byte *    getLine( Byte * p, FILE * fp, int Cmnt );
  229. void    killNets( void );
  230. int    main( int argc, Byte * argv[] );
  231. void    makeDir( Byte * p );
  232. void    makeName( Byte * p );
  233. void    mapNets( void );
  234. int    needed( tAd a );
  235. tNod *    newNod( void );
  236. void    parseAd( Byte * p, tAd * a );
  237. void    parseRec( Byte * Line, tNod * Buf, int Action );
  238. int    polz( eTyp Type, tAd a );
  239. int    ptCmp( tNod ** p, tNod ** q );
  240. void    readCfg( Byte * cfgName );
  241. void    readInfd199b( void );
  242. void    readPointnet( void );
  243. void    readUserlist( void );
  244. void    removeNets( void );
  245. void    wrt199bList( FILE * of );
  246. void    wrtClist( FILE * of );
  247. void    wrtList( FILE * fp, FILE * of );
  248. void    wrtRec( tNod * p, FILE * of, YesNo Fd199b, Byte * Term );
  249. void    wrtuList( FILE * fp, FILE * of );
  250. void    wrtuRec( tNod * p, FILE * of );
  251. /* ========================================================================= */
  252.